#Include <Misc.au3>

#cs

This is the old version of FickyFocus.  It is too sluggish to be useful to me.  It doesn't work with a hotkey but instead tries to detect if a user had clicked on the Windows taskbar (and if so, it allows the focus to change).  It also allows focus change if you right-click anywhere.  The problem is that you need to hold down your mouse button for about a second before the script realises that you had pressed it.  It assumes the taskbar is 200 pixels high, so change that value to suit.

#ce

$dll = DllOpen("user32.dll")

Sleep ("2000") ; script waits 2 seconds before detecting its first window

Global $hWndActive = WinGetHandle("[ACTIVE]") ; get active window's handle

Global $taskbar = @DesktopHeight - 200

While 1
If _IsPressed("01", $dll) Then ; if left-click
Didleftclick()
EndIf

If _IsPressed("02", $dll) Then ; if right-click
Didrightclick()
EndIf

If WinExists ($hWndActive) Then ; does previous active window still exist?
WinActivate($hWndActive) ; activate it
Else
Reidentify()
EndIf

WEnd

Func Didleftclick()
Local $leftclickpos = MouseGetPos ()
If $leftclickpos[1] > $taskbar Then ; if left-click was on or near taskbar
Sleep ("3000") ; wait 3 seconds
Global $hWndActive = WinGetHandle("[ACTIVE]") ; get active window's handle
EndIf
EndFunc

Func Didrightclick()
Sleep ("100") ; wait 10th of a second
Global $hWndActive = WinGetHandle("[ACTIVE]") ; get active window's handle
EndFunc

Func Reidentify()
Global $hWndActive = WinGetHandle("[ACTIVE]") ; get active window's handle
EndFunc

